package com.yanqu.road.server.logic.activity.condition.normal;

import com.yanqu.road.entity.activity.ActivityConditionInfo;
import com.yanqu.road.entity.activity.ActivityInfo;
import com.yanqu.road.entity.enums.eGamePlayerEventType;
import com.yanqu.road.entity.enums.ePlayerAttrType;
import com.yanqu.road.server.gameplayer.GamePlayer;
import com.yanqu.road.server.gameplayer.module.player.AttributeModule;
import com.yanqu.road.server.gameplayer.module.task.TaskModule;
import com.yanqu.road.server.logic.activity.BaseActivityData;
import com.yanqu.road.server.logic.activity.condition.BaseActivityCondition;

import java.math.BigInteger;

/**
 * 门客基金
 */
public class PatronsFundCondition extends BaseActivityCondition {

	public PatronsFundCondition(ActivityInfo activityInfo, ActivityConditionInfo activityConditionInfo, BaseActivityData baseActivityData) {
		super(activityInfo, activityConditionInfo, baseActivityData);
	}

	@Override
	public void addTrigger(GamePlayer player) {
		player.getModule(TaskModule.class).getGameEvent().addListener(eGamePlayerEventType.PatronsFund.getValue(), handle);
	}

	@Override
	public void removeTrigger(GamePlayer player) {
		player.getModule(TaskModule.class).getGameEvent().removeListener(eGamePlayerEventType.PatronsFund.getValue(), handle);
	}

	public boolean isCompleted(GamePlayer player) {
		//第一位是是否要購買過
		if(activityConditionInfo.getParamList().get(0).compareTo(BigInteger.ONE) == 0){
			//是否購買了
			if(player.getModule(AttributeModule.class).getAttribute(ePlayerAttrType.PatronsFund) == 1){
				return getValue().compareTo(activityConditionInfo.getParamList().get(3)) >= 0;
			}
		}else if(activityConditionInfo.getParamList().get(0).compareTo(BigInteger.ZERO) == 0){
			return getValue().compareTo(activityConditionInfo.getParamList().get(3)) >= 0;
		}
		return false;
	}

	@Override
	public void initDefaultValue() {
		setValue(BigInteger.valueOf(player.getTitleId()));
	}

	@Override
	protected void player_BoardLevelHandle(Object object) {
		int args = (int)object;
		setValue(BigInteger.valueOf(args));
	}

}
